﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UniRlv.COL;
using UniRlv.Utility;

namespace UniRlv.UI.Main.SystemManage
{
    public partial class FrmAddOrEditProductionLine : UniRlv.UI.Main.DialogBase
    {
        public ProductionLine info { get; set; }
        public FrmAddOrEditProductionLine()
        {
            InitializeComponent();
        }

        private void FrmAddOrEditProductionLine_Load(object sender, EventArgs e)
        {
            if (this.Tag == null)
            {
            }
            else
            {
                info = this.Tag as ProductionLine;
                ShowInfo(info);

            }
        }

        private void ShowInfo(ProductionLine info)
        {
            txtName.Text = info.name;
            txtRemark.Text = info.remarks;
            txtResponser.Text = info.responser;
            txtWorkshop.Text = info.workshopName;
            numStationQty.Value = info.stationQuantity;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                ShowWarnMessageBox("提示", "产线名称不能为空！");
                txtName.Focus();
                return;
            }

            if (string.IsNullOrEmpty(txtWorkshop.Text))
            {
                ShowWarnMessageBox("提示", "车间/仓库不能为空！");
                txtWorkshop.Focus();
                return;
            }

            if (info == null)
            {
                info = new ProductionLine();
                info.ID = DALOpr.GetNextObjectID("ProductionLine");
                info.createTime = DateTime.Now;
                info.creator = PublicObject.CurUser.name;
            }

            info.name = txtName.Text;
            info.remarks = txtRemark.Text;
            info.stationQuantity = Convert.ToInt32(numStationQty.Value);
            info.workshopName = txtWorkshop.Text;
            info.responser = txtResponser.Text;

            this.Tag = info;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
    }
}
